class Solution:
    def minimumTotal(self, triangle: list) -> int:
        len_tri = len(triangle)
        if len_tri == 0:
            return 0
        for i in range(1, len_tri):
            triangle[i][0] += triangle[i-1][0]
            triangle[i][-1] += triangle[i-1][-1]
            for j in range(1, i):
                triangle[i][j] += min(triangle[i-1][j], triangle[i-1][j-1])
        return min(triangle[-1])


a = Solution()
print(a.minimumTotal([[2],
                      [3, 4],
                      [6, 5, 7],
                      [4, 1, 8, 3]]))
print(a.minimumTotal([[1]]))